package com.mengyu.moeisland.utils

import android.util.Log
import java.util.Locale

object  LGG {
    val TAG="LGGLog"
    val MOREINFO=true
    val isPrint= true
    fun e(tag:String?, msg:Any){
//      val tagger= tag.takeIf { it!=null }
        if(!isPrint){
            return
        }
        if(MOREINFO){
            Log.e("$tag","${wrapperContent()} $msg")
        }else{
            Log.e("$tag","$msg")
        }
    }

    fun e(msg:Any){
        if(!isPrint){
            return
        }
        if(MOREINFO){
            Log.e("$TAG","${wrapperContent()} $msg")
        }else{
            Log.e("$TAG","$msg")
        }
    }
    private const val SUFFIX = ".java"
    private fun wrapperContent(): String {
        val stackTrace = Thread.currentThread().stackTrace
        val targetElement = stackTrace[5]
        var className = targetElement.className
        val classNameInfo = className.split("\\.").toTypedArray()
        if (classNameInfo.size > 0) {
            className = classNameInfo[classNameInfo.size - 1] +  SUFFIX
        }
        if (className.contains("$")) {
            className = className.split("\\$").toTypedArray()[0] + SUFFIX
        }
        val methodName = targetElement.methodName
        var lineNumber = targetElement.lineNumber
        if (lineNumber < 0) {
            lineNumber = 0
        }
        val methodNameShort = methodName.substring(0, 1).uppercase(Locale.getDefault()) + methodName.substring(1)
        return   "[ ($className:$lineNumber)#$methodNameShort ] \n"
    }


}